'''
    student.py

        The student.py module contains just one class called
        'student' which manages all the information a particular
        student has in the system
    
        student

            The 'student' class is used by the system to 
            contain all the information of a student, such
            as GPA, all the courses taken and being taken
            and major/minor of the student, in an object
'''

import course_manager

'''
    student

    The 'student' class is used by the system to 
    contain all the information of a student, such
    as GPA, all the courses taken and being taken
    and major/minor of the student, in an object
'''
class student:
    
    '''
        __init__()

        Initializes a student with all of his/her
        relevant information: name, major, minor and courses
    '''
    def __init__(self, name, major, minor):
        self.name = name
        self.major = major
        self.minor = minor
        self._courses = course_manager.manager()
        
    '''
        get_name()

        Returns the name of the student
    '''
    def get_name(self):
        return self.name
    
    '''
        get_major()
        
        Returns the major of the student
    '''
    def get_major(self):
        return self.major
    
    '''
        get_minor()

        Returns the minor of the student
    '''
    def get_minor(self):
        return self.minor
    
    '''
        get_valid_semesters()

        Returns all the semesters a user has in
        his/her plan
    '''
    def get_valid_semesters(self, course, year):
        return self._courses.get_valid_semesters(course, year)
    
    '''
        get_courses()

        Returns all the courses a student has taken
    '''
    def get_courses(self):
        return self._courses.all_taken();
    
    '''
        can_add()

        Checks if a class can be added to a particular semester
    '''
    def can_add(self, prereqs, semester):
        return self._courses.can_add(prereqs, semester)
    
    '''
        add()

        Adds a course to a particular semester
    '''
    def add(self, course, semester):
        self._courses.add(course, semester)
        
    '''
        remove_effects()

        Returns courses that need to be removed from
        the plan due to requirements failure
    '''
    def remove_effects(self, course, semester, dependants):
        return self._courses.remove_effects(course, semester, dependants)
    
    '''
        remove_course()

        Removes a course from a particular semester
    '''
    def remove_course(self, course, semester):
        self._courses.remove(course.get_id(), semester)
        
    '''
        courses_being_taken()

        Returns courses that are being taken in a particular semester
    '''
    def courses_being_taken(self, semester):
        return self._courses.courses_being_taken(semester)
    
    '''
        has_taken()

        Checks if the course has been taken already
    '''
    def has_taken(self, course):
        return self._courses.has_taken(course)
    
    '''
        can_remove()

        Checks if the course can be removed
    '''
    def can_remove(self, course, semester):
        return self._courses.can_remove(course, semester)
    
    '''
        change_grade()

        Allows the student to change the course grade
    '''
    def change_grade(self, course, semester, grade):
        self._courses.change_grade(course, semester, grade)
        
    '''
        get_student_info()

        Returns student information including: GPA, total credits and all of
        the student's courses
    '''
    def get_student_info(self):
        gpa_vals = {"A":4, "B":3, "C":2, "D":1, "F":0}
        cur_courses = self._courses.all_taken()

	graded_courses = []
        total_earned = 0.0
        total_credits = 0.0
        
        for course in cur_courses:
            grade = course.get_grade()
            cred = course.get_credits()
            if(grade in gpa_vals and cred != 1.5):
                total_credits = total_credits + cred
                total_earned = total_earned + (gpa_vals[grade] * cred)
		graded_courses.append(course)
        
	if(total_credits != 0.0):    
        	total_gpa = total_earned/total_credits
	else:
		total_gpa = 0.0
        
        return total_gpa, total_credits, graded_courses
            
            
        
        
        
        
